package collection02;

import java.util.ArrayList;
import java.util.List;

public class ListDemo2 {
    public static void main(String[] args) {
        //创建集合对象
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list: "+list);//list: [one, two, three, four, five]
        System.out.println("----------------------");

        list.add(3,"six");//下标为3的位置插入元素
        System.out.println("list:"+list);//list: [one, two, three, six, four, five]

        //若add()下标为最后一个元素的下一个位置, 则相当于追加操作
        list.add(6,"seven");//下标6位置插入元素
        System.out.println("list:"+list);//list: [one, two, three, six, four, five, seven]

        //list.remove(2); //下标2位置的元素删除 --- 常规操作
        String s = list.remove(2);//删除下标为2的元素, 并将被删除元素返回给s
        System.out.println(s);//three
        System.out.println("list:"+list);//list: [one, two, six, four, five, seven]

    }
}
